/*
 * Created on Mar 17, 2004
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package schoolsource.command;

import java.io.IOException;
import java.util.Enumeration;
import java.util.logging.Level;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import schoolsource.gui.FormFields;
import schoolsource.util.SchoolLogger;

/**
 * @author Steven Steele
 * 
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class LoginCMD extends HttpServlet {
	/**
	 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse)
	 */
	public void doPost(HttpServletRequest input, HttpServletResponse response)
			throws ServletException, IOException {

		//SchoolLogger.logger.log(Level.INFO, "request: "
		//		+ input.getQueryString());

		// Set up request dispatcher to display the next page.
		RequestDispatcher disp;
		ServletContext sc = getServletContext();

		Enumeration e = input.getParameterNames();
		String s;
		//SchoolLogger.logger.log(Level.INFO, "List parameter values");
		while (e.hasMoreElements()) {
			s = (String) e.nextElement();
			//SchoolLogger.logger.log(Level.INFO, s + ":  "
				//	+ input.getParameter(s));
		}

		String schoolName = input.getParameter(FormFields.SCHOOLNAME);
		String accessType = input.getParameter(FormFields.USRTYPE);

		input.setAttribute(FormFields.USRTYPE, accessType);
		input.setAttribute(FormFields.SCHOOLNAME, schoolName);
		if (FormFields.STUDENTTYPE.equalsIgnoreCase(accessType)
				|| FormFields.PARENTTYPE.equalsIgnoreCase(accessType)) {

			input.setAttribute(FormFields.SCHOOLNAME, schoolName);
			disp = sc.getRequestDispatcher("/jsp/Access.jsp");

		} else if (FormFields.TEACHERTYPE.equalsIgnoreCase(accessType)) {
			disp = sc.getRequestDispatcher("/jsp/Access.jsp");
		} else if (FormFields.EDITORTYPE.equalsIgnoreCase(accessType)) {
			disp = sc.getRequestDispatcher("/jsp/Access.jsp");
		} else {
			disp = sc.getRequestDispatcher("/blank.html");
		}

		response.setContentType("text/html; charset=ISO-8859-2");
		disp.include(input, response);
		disp.forward(input, response);
	}

	/**
	 * Forwards all calls to doPost
	 * 
	 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse)
	 */
	public void doGet(HttpServletRequest input, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(input, response);

	}

}
